import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/http/special_code_pop.dart';
import 'package:pornhub_app/services/storage_service.dart';
import 'package:pornhub_app/utils/consts.dart';
import 'package:restart_app/restart_app.dart';
import 'package:universal_html/html.dart' show window;

class RestartApp extends StatefulWidget {
  const RestartApp({super.key});

  @override
  State<StatefulWidget> createState() => _RestartApp();
}

class _RestartApp extends State<RestartApp> {
  final storageService = Get.find<StorageService>();
  @override
  void activate() {
    SmartDialog.showLoading(
      msg: '',
      animationBuilder: (controller, child, animationParam) {
        return SpecialCodePop(
          desc: "请点击确定重新初始化app",
          tap: () {
            storageService.deleteBox(
              Consts.generalBoxName,
            );
            if (kIsWeb) {
              window.location.reload();
            } else {
              SmartDialog.dismiss();
              Restart.restartApp();
            }
          },
        );
      },
      alignment: Alignment.center,
    );
    super.activate();
  }

  @override
  Widget build(BuildContext context) {
    return FlutterSmartDialog(
      child: Container(
          width: double.infinity, height: double.infinity, color: Colors.black),
    );
  }
}
